package com.example.win.android_banduyujia.venuesactivity.activity.openactivity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.RadioGroup;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.adapter.ViewPageAdapter;
import com.example.win.android_banduyujia.peopleactivity.fragment.projectfragment.fragment.CompleteFragment;
import com.example.win.android_banduyujia.peopleactivity.fragment.projectfragment.fragment.DropFragment;
import com.example.win.android_banduyujia.peopleactivity.fragment.projectfragment.fragment.WaitFragment;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;

import java.util.ArrayList;

/**
 * Created by huchun on 2015/8/17.
 */
public class VenuesMyProjectActivity extends BaseTitleBarActivity {
    public static final String TAG = VenuesMyProjectActivity.class.getSimpleName();

    private RadioGroup  mProRG;
    private ViewPager   mViewPager;

    private  ArrayList<Fragment>  mFragmentList=new ArrayList<Fragment>();
    private  ViewPageAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_page_my_project);

        InitTitles();
        InitFragemnt();
        InitViews();
    }

    private void InitTitles() {
        showLeftBackButton();
        setTitle(R.string.fragment_my_course);
    }

    private void InitFragemnt() {
         WaitFragment     waitFragment     = new  WaitFragment();
         CompleteFragment completeFragment = new  CompleteFragment();
         DropFragment     dropFragment     = new  DropFragment();
         mFragmentList.add(waitFragment);
         mFragmentList.add(completeFragment);
         mFragmentList.add(dropFragment);
    }

    @Override
    protected void onResume() {
        super.onResume();

        mAdapter = new ViewPageAdapter(getSupportFragmentManager(), mFragmentList);
        mViewPager.setAdapter(mAdapter);
    }

    private void InitViews() {
        mProRG = (RadioGroup)findViewById(R.id.radio_group_my_project);
        mProRG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio_edit_class:
                         mViewPager.setCurrentItem(0);
                        break;
                    case R.id.radio_review_complete:
                        mViewPager.setCurrentItem(1);
                        break;
                    case R.id.radio_review_drop:
                        mViewPager.setCurrentItem(2);
                        break;
                }
            }
        });

        mViewPager = (ViewPager)findViewById(R.id.my_project_viewPager);
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) {   }

            @Override
            public void onPageSelected(int i) {
                switch (i){
                    case 0:
                        mProRG.check(R.id.radio_edit_class);
                        break;
                    case 1:
                        mProRG.check(R.id.radio_review_complete);
                        break;
                    case 2:
                        mProRG.check(R.id.radio_review_drop);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) { }
        });


    }
}
